<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="../common/taglibs.jsp" %>
<%
    response.setHeader("Pragma", "No-cache");
	response.setHeader("Cache-Control", "no-cache");
	response.setDateHeader("Expires", 0);
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<jsp:include page="/page/common/include.jsp"></jsp:include>
<script language="javascript" type="text/javascript">

$(document).ready(function(){
	
	/** 初始化查询面板 */
	$("#searchPanel").panel({
		collapsible:true,
		border:false,
		closable:true
	});
	
	/** 初始化编辑窗口 */
	$("#editDiv").window({
		title:'修改资源信息',
		width:400,
		height:300,
		modal:true,
		closed:true,
		minimizable:false,
		maximizable:false
	});
	
	/** 初始化查看窗口 */
	$("#viewDiv").window({
		title:'查看资源信息',
		width:600,
		height:320,
		modal:true,
		closed:true,
		minimizable:false,
		maximizable:false
	});
	
	/** 初始化资源信息Grid Table */
	$("#gridTable").datagrid({
		title:"资源信息列表",
		url:'<%=request.getContextPath()%>/functionInfo/functionInfoAction!listFunctionInfo.do',
		singleSelect:true,
		rownumbers:true,
		striped:true,
		fitColumns:true,
		pagination:true,
		toolbar:"#toolbar",
		columns:[[
       		{field:'sysCode',title:'系统编号',width:80},
          	{field:'funcCode',title:'资源编号',width:100},
          	{field:'funcName',title:'资源名称',width:100,align:'right'},
          	{field:'funcUrl',title:'资源地址',width:250,align:'right',formatter:funcUrlFormatter},
          	{field:'funcType',title:'资源类型',width:70,align:'right',formatter:funcTypeFormatter},
          	{field:'parentFuncCode',title:'父资源编号',width:100,align:'right'},
          	{field:'orderIndex',title:'排序号',width:50,align:'right'},
          	{field:'version',title:'版本号',hidden:true}
     	]],
     	onClickRow:function(rowIndex,rowData){
     		
     	},
     	onBeforeLoad:function(){
     		disableLinkButton();
     	},
		onLoadSuccess:function(){
			enableLinkButton();
			$(".func_url_tooltip").tooltip();
		}
	});
	
});

/**
 * 资源地址ToolTip
 */
function funcUrlFormatter(value,rowData){
	return "<span class='func_url_tooltip' title='"+value+"'>"+value+"</span>";
}

/**
 * 资源类型名称格式化
 */
function funcTypeFormatter(value, rowData) {
	if (value == '0') {
		return "模块节点";
	} else if (value == '1') {
		return "菜单节点";
	} else if (value == '2') {
		return "功能节点";
	} else {
		return "";
	}
}

/**
 * 编辑资源信息
 */
function edit() {
	var rowData = $('#gridTable').datagrid('getSelected');
	if(rowData == null){
		messageAlertWarning("操作提示","请选择要修改的资源信息！");
		return;
	}
	$.ajax({
		url : '<%=request.getContextPath()%>/functionInfo/functionInfoAction!initEditFunctionInfo.do',
		type : 'post',
		dataType : 'text',
		cache : false,
		data : {
			sysCode : rowData.sysCode,
			funcCode: rowData.funcCode,
			version : rowData.version
		},
		success : function(data) {
			var j = JSON.parse(data);
			if (j.result = 'success') {
				var editFuncInfoDiv = initEditWindow(JSON.parse(j.msg));
				editFuncInfoDiv.window("open");
			} else {
				$.messager.alert('通知', j.msg,'warning');
				$("#gridTable").datagrid("reload");
			}
		}
	});
}

/**
 * 初始化编辑窗口
 */
function initEditWindow(rowData){
	   return $("#editDiv").window({
			onBeforeOpen:function(){
				$("#parentFuncCode_edit").combotree();
				$("#funcType_edit").combobox({
					panelHeight:'auto',
					valueField:'id',
					textField:'text',
					onChange:function(newValue,oldValue){
						clearParentFuncCodeInput();
						if(newValue == ''){
							$("#parentFuncCode_edit").combotree("disable");
						}else{
							$("#parentFuncCode_edit").combotree("enable");
							setParentFunctionCodeValue($('#sysCode_edit').val(),newValue,null);
						}
					}
				});
				initFuncTypeInputData();
				resetFormValue(rowData);
				setParentFunctionCodeValue(rowData.sysCode,rowData.funcType,rowData.parentFuncCode);
			},
			onBeforeClose:function(){
				resetFormValue(null);
			}
		});
}

/**
 * 初始化和设置父资源下拉列表的值
 */
function setParentFunctionCodeValue(sysCode,funcType,parentFunctionCodeValue){
	$.ajax({
		url : '<%=request.getContextPath()%>/functionInfo/functionInfoAction!getFuncInfoComboxValue.do',
		type : 'post',
		dataType : 'text',
		cache : false,
		data : {
			sysCode : sysCode,
			funcType : funcType
		},
		success : function(data) {
			$("#parentFuncCode_edit").combotree('loadData',eval(data));
			if(parentFunctionCodeValue != null){
				$("#parentFuncCode_edit").combotree("setValue",parentFunctionCodeValue);
			}
		}
	});
}

/**
 * 修改页面提交
 */
function editWindowSubmit() {
	var funcInfo = JSON.stringify(getFormValue());
	$.ajax({
		url : '<%=request.getContextPath()%>/functionInfo/functionInfoAction!editFunctionInfo.do',
		type : 'post',
		dataType : 'text',
		cache : false,
		data : {
			funcInfo : funcInfo
		},
		success : function(data) {
			var j = JSON.parse(data);
			if (j.result = 'success') {
				$.messager.alert('操作结果', '资源信息修改成功！', 'info');
				editWindowClose();
				$("#gridTable").datagrid("reload");
			} else {
				$.messager.alert('操作结果', j.msg, 'error');
			}
		}
	});
}
	
/**
 * 	清空表单内容
 */
function resetFormValue(rowData){
	if(rowData == null){
		$("#funcName_edit").val('');
		$("#funcUrl_edit").val('');
		$("#orderIndex_edit").val(''),
		$("#version_edit").val(0)
	}else{
		$("#sysCode_edit").val(rowData.sysCode);
		$("#funcCode_edit").val(rowData.funcCode);
		$("#funcName_edit").val(rowData.funcName);
		$("#funcType_edit").combobox("setValue",rowData.funcType);
		$("#funcUrl_edit").val(rowData.funcUrl);
		$("#orderIndex_edit").val(rowData.orderIndex),
		$("#version_edit").val(rowData.version)
	}
}

/**
 * 删除资源信息
 */
function remove() {
	var rowData = $('#gridTable').datagrid('getSelected');
	if(rowData == null){
		messageAlertWarning("操作提示","请选择要删除的资源信息！");
		return;
	}
	messageConfirm("操作提示",'你确定要删除所选的资源信息吗?',removeCallback);
}

/**
 * 删除操作回调函数
 */
function removeCallback(){
	var rowData = $('#gridTable').datagrid('getSelected');
	$.ajax({
		url : '<%=request.getContextPath()%>/functionInfo/functionInfoAction!deleteFunctionInfo.do',
		type : 'post',
		dataType : 'text',
		cache : false,
		data : {
			sysCode : rowData.sysCode,
			funcCode : rowData.funcCode,
			version : rowData.version
		},
		success : function(data) {
			var j = JSON.parse(data);
			if (j.result = 'success') {
				$.messager.alert('操作结果', '系统信息删除成功！','info');
				$("#gridTable").datagrid("reload");
			} else {
				$.messager.alert('操作结果', j.msg,'error');
			}
		}
	});
}

/**
 * 查看
 */
function view(){
	var rowData = $('#gridTable').datagrid('getSelected');
	if(rowData == null){
		messageAlertWarning("操作提示","请选择要查看的资源信息！");
		return;
	}
	$.ajax({
		url : '<%=request.getContextPath()%>/functionInfo/functionInfoAction!initEditFunctionInfo.do',
		type : 'post',
		dataType : 'text',
		cache : false,
		data : {
			sysCode : rowData.sysCode,
			funcCode: rowData.funcCode,
			version : rowData.version
		},
		success : function(data) {
			var j = JSON.parse(data);
			if (j.result = 'success') {
				var viewFuncInfoDiv = initViewWindow(JSON.parse(j.msg));
				viewFuncInfoDiv.window("open");
			} else {
				$.messager.alert('通知', j.msg,'warning');
				$("#gridTable").datagrid("reload");
			}
		}
	});
}

/**
 * 初始化查看窗口
 */
function initViewWindow(functionInfo){
	   return $("#viewDiv").window({
			onBeforeOpen:function(){
				$("#sysName_view").text(functionInfo.sysName);
				$("#funcCode_view").text(functionInfo.funcCode);
				$("#funcName_view").text(functionInfo.funcName);
				$("#funcTypeName_view").text(functionInfo.funcTypeName);
				$("#funcUrl_view").text(functionInfo.funcUrl);
				$("#parentFuncCode_view").text(functionInfo.parentFuncCode);
				$("#orderIndex_view").text(functionInfo.orderIndex);
				var funcStatusNameFormat = "";
				if(functionInfo.funcStatus == '0'){
					funcStatusNameFormat = "<span style='color:green;'>"+functionInfo.funcStatusName+"</span>";
				}else if(functionInfo.funcStatus == '1'){
					funcStatusNameFormat = "<span style='color:red;'>"+functionInfo.funcStatusName+"</span>";
				}
				$("#funcStatusName_view").html(funcStatusNameFormat);
				$("#recordCrtOperLoginName_view").text(functionInfo.recordCrtOperLoginName);
				$("#recordCrtTime_view").text(functionInfo.recordCrtTime);
				$("#recordUpdOperLoginName_view").text(functionInfo.recordUpdOperLoginName);
				$("#recordUpdTime_view").text(functionInfo.recordUpdTime);
				$("#version_view").text(functionInfo.version);
			},
			onBeforeClose:function(){
				
			}
		});
}

/**
 * 关闭查看窗口
 */
function viewWindowClose() {
	$("#viewDiv").window("close");
}

/**
 * 获取表单的值
 */
function getFormValue() {
	var funcInfo = {
		sysCode : $('#sysCode_edit').val(),
		funcCode : $("#funcCode_edit").val(),
		funcName : $("#funcName_edit").val(),
		funcType : $('#funcType_edit').combobox('getValue'),
		funcUrl : $("#funcUrl_edit").val(),
		parentFuncCode : $('#parentFuncCode_edit').combobox('getValue'),
		orderIndex : $("#orderIndex_edit").val(),
		version : $("#version_edit").val()
	};
	return funcInfo;
}

/**
 * 关闭修改窗口
 */
function editWindowClose() {
	$("#editDiv").window("close");
}

/**
 * 初始化资源类型下拉列表
 */
function initFuncTypeInputData(){
	$("#funcType_edit").combobox("loadData",[{id:'',text:'请选择'},{id:'0',text:'模块节点'},{id:'1',text:'菜单节点'},{id:'2',text:'功能节点'}]);
	$("#funcType_edit").combobox("setValue",'');
}

/**
 * 重置父资源下拉列表
 */
function clearParentFuncCodeInput(){
	 $("#parentFuncCode_edit").combotree("clear");
	 $("#parentFuncCode_edit").combotree("loadData",[{id:'',text:'请选择'}]);
	 $("#parentFuncCode_edit").combotree("setValue",'');
}

/**
 * 查询资源信息
 */
function funcInfoSearch(){
	$("#sysCode_search").val($.trim($("#sysCode_search").val()));
	$("#funcCode_search").val($.trim($("#funcCode_search").val()));
	$("#funcName_search").val($.trim($("#funcName_search").val()));
	$("#gridTable").datagrid("load",{
		sysCode:$("#sysCode_search").val(),
		funcCode:$("#funcCode_search").val(),
		funcName:$("#funcName_search").val(),
		funcType:$('#funcType_search').combobox('getValue')
	});
}

/**
 * 清空查询条件
 */
function clearSearchCriteria(){
	goToPage('<%=request.getContextPath()%>/functionInfo/functionInfoAction!initFunctionInfo.do');
}
</script>
</head>

<body style="background: white;">
	<!-- 查询面板 -->
	<div id="searchPanel" style="width:'100%';height:95px;padding:20px;" align="center">
	    <table>
	    	<tr>
	    		<td>系统编号：<input id="sysCode_search" type="text" style="width:100px"></td>
	    		<td>资源编号：<input id="funcCode_search" type="text" style="width:100px"></td>
	    		<td>资源名称：<input id="funcName_search" type="text" style="width:100px"></td>
	    		<td>
	    			资源类型：<select class="easyui-combobox" id="funcType_search" data-options="panelHeight:'auto'" style="width:100px">
					<option value="">请选择</option>
					<option value="0">模块节点</option>
					<option value="1">菜单节点</option>
					<option value="2">功能节点</option>
				 </select>
	    		</td>
	    	</tr>
	    	<tr>
	    		<td colspan="4" align="center" style="padding-top: 10px">
	    			<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" onclick="funcInfoSearch()">查询</a>
					<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-reload" onclick="clearSearchCriteria()">清空</a>
	    		</td>
	    	</tr>
	    </table>
	</div>
	
	<!-- 工具栏 -->
	<div id="toolbar" style="padding:5px;">
		<a href="javascript:void(0)" id="editBtn" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-edit'" onclick="edit()">修改</a>
		<a href="javascript:void(0)" id="removeBtn" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-remove'" onclick="remove()">删除</a>
		<a href="javascript:void(0)" id="viewBtn" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-remove'," onclick="view()">查看</a>
	</div>
	
	<!-- 数据Table -->
	<table id="gridTable" style="width:'90%';height:'100%'">
	</table>
	
	<!-- 编辑窗口 -->
	<div id="editDiv" style="padding:10px;">
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center'" style="padding:10px;" align="center">
		    	<table>
		    		<s:hidden name="version_edit" value="0"/>
		    		<tr>
		    			<td>业务系统:</td>
		    			<td>
							<input id="sysCode_edit" type="text" disabled="disabled"/>
		    			</td>
		    		</tr>
		    		<tr>
		    			<td>资源编号:</td>
		    			<td><input id="funcCode_edit"  type="text" disabled="disabled"/></td>
		    		</tr>
		    		<tr>
		    			<td>资源名称:</td>
		    			<td>
		    				<input id="funcName_edit"  type="text" />
		    			</td>
		    		</tr>
		    		<tr>
		    			<td>资源类型:</td>
		    			<td>
		    				<input id="funcType_edit" style="width:154px;">
							 </input>
		    			</td>
		    		</tr>
		    		<tr>
		    			<td>资源地址:</td>
		    			<td>
		    				<input id="funcUrl_edit"  type="text" />
		    			</td>
		    		</tr>
		    		<tr>
		    			<td>父节点:</td>
		    			<td>
							 <input id="parentFuncCode_edit" style="width:154px;">
		    			</td>
		    		</tr>
		    		<tr>
		    			<td>排序号:</td>
		    			<td>
		    				<input id="orderIndex_edit" class="easyui-numberbox" data-options="min:0"/>
		    			</td>
		    		</tr>
		    	</table>
			</div>
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
				<a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="editWindowSubmit()">提交</a>
				<a class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" href="javascript:void(0)" onclick="editWindowClose()">取消</a>
			</div>
		</div>
	</div>
	
	<!-- 查看窗口 -->
	<div id="viewDiv" style="padding:10px;">
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center'" style="padding:10px;" align="center">
		    	<table class="view_table">
		    		<tr>
		    			<th>系统名称</th>
		    			<td id="sysName_view"/>
		    			<th>资源编号</th>
		    			<td id="funcCode_view"/>
		    		</tr>
		    		<tr>
		    			<th>资源名称</th>
		    			<td id="funcName_view"/>
		    			<th>资源类型</th>
		    			<td id="funcTypeName_view"/>
		    		</tr>
		    		<tr>
		    			<th>资源地址</th>
		    			<td id="funcUrl_view"/>
		    			<th>父节点</th>
		    			<td id="parentFuncCode_view"/>
		    		</tr>
		    		<tr>
		    			<th>排序号</th>
		    			<td id="orderIndex_view"/>
		    			<th>资源状态</th>
		    			<td id="funcStatusName_view"/>
		    		</tr>
		    		<tr>
		    			<th>记录创建人</th>
		    			<td id="recordCrtOperLoginName_view"/>
		    			<th>记录创建时间</th>
		    			<td id="recordCrtTime_view"/>
		    		</tr>
		    		<tr>
		    			<th>记录更新人</th>
		    			<td id="recordUpdOperLoginName_view"/>
		    			<th>记录更新时间</th>
		    			<td id="recordUpdTime_view"/>
		    		</tr>
		    		<tr>
		    			<th>版本号</th>
		    			<td id="version_view"/>
		    			<th></th>
		    			<td></td>
		    		</tr>
		    	</table>
			</div>
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
				<a class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" href="javascript:void(0)" onclick="viewWindowClose()">关闭</a>
			</div>
		</div>
	</div>
</body>
</html>